package me.luger.consumer.controller;

import me.luger.dubbo3.entity.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloApiController {

    @DubboReference
    private DubboGreeterGrpc.IGreeter greeter;

    @DubboReference
    private DubboMusicServiceGrpc.IMusicService musicService;

    @RequestMapping("/hello")
    public String hello(@RequestParam("name") String name) {
//        Properties properties = System.getProperties();
//        System.out.printf(properties.toString());
//        System.out.printf(properties.propertyNames().toString());
        HelloRequest request = HelloRequest.newBuilder().setName(name).build();
        HelloReply response = greeter.sayHello(request);
        return response.getMessage();
    }

    @RequestMapping("/music")
    public Object music(@RequestParam("id") Long id) {

        GetMusicByIdReply musicByIdReply = musicService.getMusicById(GetMusicByIdRequest.newBuilder().setId(id).build());
        return musicByIdReply;
    }
}
